const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const { merge } = require("webpack-merge");
const nodeExternals = require("webpack-node-externals");

const baseConfig = {
  mode: "development",
  devtool: false,
  entry: "./src/index.js",
  externals: [
    // nodeExternals(), // 排除所有第三方模块，就是把node_modules里的模块全部设置为外部模块
  ],
  output: {
    // library: "math",
    clean: true,
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: "babel-loader",
            options: {
              targets: {
                browsers: [">1%"],
              },
              presets: [
                [
                  "@babel/preset-env",
                  {
                    useBuiltIns: false,
                    // corejs: 3,
                  },
                ],
              ],
              plugins: [
                [
                  "@babel/plugin-transform-runtime",
                  {
                    corejs: 3,
                    helpers: true,
                    regenerator: true,
                  },
                ],
              ],
            },
          },
        ],
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin(),
    // new webpack.DefinePlugin({
    //   "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
    // }),
  ],
};

module.exports = baseConfig;

// module.exports = [
//   merge(baseConfig, {
//     // output: {
//     //   filename: "[name]-commonjs.js",
//     //   libraryTarget: "commonjs2",
//     // },
//   }),
//   // merge(baseConfig, {
//   //   output: {
//   //     filename: "[name]-umd.js",
//   //     libraryTarget: "amd",
//   //   },
//   // }),
// ];
